package core;

import java.util.Arrays;

import javax.swing.JTable;

public class Utilities {
	public static int[] getSortedSelectionRows(JTable table) {
		
		int[] rows = mapSelectionRowsToModel(table);
		
		// sort to account for the shifting row indices when removing
		Arrays.sort(rows);
		
		return rows;
	}
	
	public static int[] mapSelectionRowsToModel(JTable table) {
		int[] selRows = table.getSelectedRows();
		
		for (int i=0; i<selRows.length; i++) 
			selRows[i] = table.convertRowIndexToModel(selRows[i]);
		
		return selRows;
	}
	
	public static boolean isMember(int n, int[] ary) {
		for (int i=0; i<ary.length; i++)
			if (ary[i] == n)
				return true;
		
		return false;
	}
}
